package com.mock.action.address;

import java.util.ArrayList;
import java.util.List;

import com.mock.action.AbstractAction;
import com.mock.dao.AddressDao;
import com.mock.dao.impl.AddressDaoImp;
import com.mock.dao.impl.ContactDaoImpl;
import com.mock.model.Address;
import com.mock.model.Country;
import com.mock.model.County;
import com.mock.model.DataTable;
import com.mock.model.Town;


public class AddressAction extends AbstractAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3813998041719775393L;
	
	List<Address> addressList;
	List<Town> townList;
	List<Country> countryList;
	List<County> countyList;
	private AddressDao addressDao = new AddressDaoImp();
	private List<ArrayList<String>> aaData = new ArrayList<ArrayList<String>>();
	private String sEcho;
	private String sSearch;
	private int iDisplayLength;
	private int iDisplayStart;
	private int iTotalRecords;
	private int iTotalDisplayRecords;
	private int iSortCol_0;
	private String sSortDir_0;
	private String sSearch_1;
	private String sSearch_4;
	private String sSearch_5;
	
	// implement function select data from ajax table
	public String addressAjaxTable(){
		
		DataTable dt = new DataTable();
		dt.sEcho = sEcho = getRequest().getParameter("sEcho");		
		dt.iDisplayStart = iDisplayStart = Integer.parseInt(getRequest()
				.getParameter("iDisplayStart"));
		dt.iDisplayLength = iDisplayLength = Integer.parseInt(getRequest()
				.getParameter("iDisplayLength"));
		dt.sSearch_1 = setsSearch_1(getRequest().getParameter("sSearch_1"));
		dt.sSearch_4 = setsSearch_4(getRequest().getParameter("sSearch_4"));
		dt.sSearch_5 = setsSearch_5(getRequest().getParameter("sSearch_5"));
		dt.iSortCol_0 = iSortCol_0 = Integer.parseInt(getRequest()
				.getParameter("iSortCol_0"));
		dt.sSortDir_0 = sSortDir_0 = getRequest().getParameter("sSortDir_0");
		
		dt.iTotalDisplayRecords = iTotalDisplayRecords = addressDao.getRowCount();
		
		List<Address> addresses = addressDao.getAddressByQuery(dt);
		for(Address address : addresses){
			ArrayList<String> newArray = new ArrayList<String>();
			newArray.add(Long.toString(address.getAddressId()));
			newArray.add(address.getAddressName1());
			newArray.add(address.getAddressName2());
			newArray.add(address.getAddressName3());
			newArray.add(address.getPostcode());
			newArray.add(address.getTown().getTownName());
			newArray.add(address.getCounty().getCountyName());
			newArray.add(address.getCountry().getCountryName());
			newArray.add(Long.toString(address.getCountry().getCountryId()));
			// add column to search
			
			aaData.add(newArray);
		}
		
		return SUCCESS;
	}
	// getter and setter
	public List<Address> getAddressList() {
		return addressList;
	}
	public void setAddressList(List<Address> addressList) {
		this.addressList = addressList;
	}
	public List<Town> getTownList() {
		return townList;
	}
	public void setTownList(List<Town> townList) {
		this.townList = townList;
	}
	public List<Country> getCountryList() {
		return countryList;
	}
	public void setCountryList(List<Country> countryList) {
		this.countryList = countryList;
	}
	public List<County> getCountyList() {
		return countyList;
	}
	public void setCountyList(List<County> countyList) {
		this.countyList = countyList;
	}
	public List<ArrayList<String>> getAaData() {
		return aaData;
	}
	public void setAaData(List<ArrayList<String>> aaData) {
		this.aaData = aaData;
	}
	public String getsEcho() {
		return sEcho;
	}
	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}
	public String getsSearch() {
		return sSearch;
	}
	public void setsSearch(String sSearch) {
		this.sSearch = sSearch;
	}
	public int getiDisplayLength() {
		return iDisplayLength;
	}
	public void setiDisplayLength(int iDisplayLength) {
		this.iDisplayLength = iDisplayLength;
	}
	public int getiDisplayStart() {
		return iDisplayStart;
	}
	public void setiDisplayStart(int iDisplayStart) {
		this.iDisplayStart = iDisplayStart;
	}
	public int getiTotalRecords() {
		return iTotalRecords;
	}
	public void setiTotalRecords(int iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}
	public int getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}
	public void setiTotalDisplayRecords(int iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}
	public int getiSortCol_0() {
		return iSortCol_0;
	}
	public void setiSortCol_0(int iSortCol_0) {
		this.iSortCol_0 = iSortCol_0;
	}
	public String getsSortDir_0() {
		return sSortDir_0;
	}
	public void setsSortDir_0(String sSortDir_0) {
		this.sSortDir_0 = sSortDir_0;
	}
	public String getsSearch_1() {
		return sSearch_1;
	}
	public String setsSearch_1(String sSearch_1) {
		this.sSearch_1 = sSearch_1;
		return sSearch_1;
	}
	public String getsSearch_4() {
		return sSearch_4;
	}
	public String setsSearch_4(String sSearch_4) {
		this.sSearch_4 = sSearch_4;
		return sSearch_4;
	}
	public String getsSearch_5() {
		return sSearch_5;
	}
	public String setsSearch_5(String sSearch_5) {
		this.sSearch_5 = sSearch_5;
		return sSearch_5;
	}
	
	
}
	
 